package cn.csxw.openchina.ui.adapter;

import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import cn.csxw.openchina.R;
import cn.csxw.openchina.base.BaseRecAdapter;
import cn.csxw.openchina.entity.bean.EventBean;
import cn.csxw.openchina.ui.activity.RecentlyDetailActivity;
import cn.csxw.openchina.utils.Global;

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

/**
 * 近期活动界面的数据获取  以及跳转到活动详情界面
 */

public class MyRecentlyAdapter extends BaseRecAdapter<EventBean> {
    @Override
    protected void onItemClick(View v, int position) {
        EventBean eventBean = mData.get(position);
//        Global.showToast("你点击了"+mData.get(position));
        if (eventBean != null) {
            Intent intent = new Intent(Global.mContext, RecentlyDetailActivity.class);
            //这个必须写 不然会报错  因为他是外部的Activity  所以需要自己打开一个
            intent.setFlags(FLAG_ACTIVITY_NEW_TASK);
            //
            intent.putExtra("RECENTLY", eventBean);
            Global.mContext.startActivity(intent);
        }
    }

    @Override
    protected BaseViewHolder getViewHolder(View itemView) {
        return new RecentlyHolder(itemView);
    }

    @Override//初始化getIntmView 布局
    protected View getItemView(ViewGroup parent) {
        return Global.inflate(R.layout.view_item_exercise, parent);
    }

    //创建一个Holder类  这里不能直接在 BaseViewHolder中创建 因为你需要实体bean的id
    class RecentlyHolder extends BaseViewHolder {
        @BindView(R.id.tv_exercise_title)
        TextView mTvExerciseTitle;
        @BindView(R.id.tv_exercise_time)
        TextView mTvExerciseTime;
        @BindView(R.id.tv_exercise_address)
        TextView mTvExerciseAddress;
        @BindView(R.id.iv_recently_photo)
        ImageView mIvExercisePhoto;

        public RecentlyHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData(EventBean activeBean, int Position) {
                /*TvExerciseTitle.setTextColor(Color.BLACK);
                mTvExerciseTime.setText("2017/1/13");*/
            if (activeBean != null) {
                mTvExerciseTitle.setText(activeBean.title);
                mTvExerciseTime.setText(activeBean.createTime);
                mTvExerciseAddress.setText(activeBean.city);
                //访问网络图片
                String cover = activeBean.cover;
                cover = cover.replace("http://192.168.1.107:8080/oschina/", "http://10.0.2.2:8080/oschina/");
                Glide.with(Global.mContext).load(cover).into(mIvExercisePhoto);
            }
        }
    }
}
